/**
  ******************************************************************************
  * @file    Project/STM32F10x_StdPeriph_Template/stm32f10x_it.c 
  * @author  MCD Application Team
  * @version V3.5.0
  * @date    08-April-2011
  * @brief   Main Interrupt Service Routines.
  *          This file provides template for all exceptions handler and 
  *          peripherals interrupt service routine.
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "headfile.h"
u8 usart_run,t,usart_finish;       //接收运行标志位，完成标志位，缓存区

//USART2_MAX_TX_LEN和USART2_MAX_RX_LEN在头文件进行了宏定义，分别指USART2最大发送长度和最大接收长度
//u8 USART1_TX_BUF[USART1_MAX_TX_LEN]; 	//发送缓冲,最大USART2_MAX_TX_LEN字节
//u8 u1rxbuf[USART1_MAX_RX_LEN];			//发送数据缓冲区1
//u8 u2rxbuf[USART1_MAX_RX_LEN];			//发送数据缓冲区2
//u8 witchbuf=0;                  		//标记当前使用的是哪个缓冲区,0：使用u1rxbuf；1：使用u2rxbuf
//u8 USART1_TX_FLAG=0;					//USART2发送标志，启动发送时置1
//u8 USART1_RX_FLAG=0;					//USART2接收标志，启动接收时置1


/** @addtogroup STM32F10x_StdPeriph_Template
  * @{
  */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/******************************************************************************/
/*            Cortex-M3 Processor Exceptions Handlers                         */
/******************************************************************************/

/**
  * @brief  This function handles NMI exception.
  * @param  None
  * @retval None
  */
void NMI_Handler(void)
{
}

/**
  * @brief  This function handles Hard Fault exception.
  * @param  None
  * @retval None
  */
void HardFault_Handler(void)
{
  /* Go to infinite loop when Hard Fault exception occurs */
  while (1)
  {
  }
}

/**
  * @brief  This function handles Memory Manage exception.
  * @param  None
  * @retval None
  */
void MemManage_Handler(void)
{
  /* Go to infinite loop when Memory Manage exception occurs */
  while (1)
  {
  }
}

/**
  * @brief  This function handles Bus Fault exception.
  * @param  None
  * @retval None
  */
void BusFault_Handler(void)
{
  /* Go to infinite loop when Bus Fault exception occurs */
  while (1)
  {
  }
}

/**
  * @brief  This function handles Usage Fault exception.
  * @param  None
  * @retval None
  */
void UsageFault_Handler(void)
{
  /* Go to infinite loop when Usage Fault exception occurs */
  while (1)
  {
  }
}

/**
  * @brief  This function handles SVCall exception.
  * @param  None
  * @retval None
  */
void SVC_Handler(void)
{
}

/**
  * @brief  This function handles Debug Monitor exception.
  * @param  None
  * @retval None
  */
void DebugMon_Handler(void)
{
}

/**
  * @brief  This function handles PendSVC exception.
  * @param  None
  * @retval None
  */
void PendSV_Handler(void)
{
}

/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{
}




//Tim2
void TIM2_IRQHandler(void)
{
   if (TIM_GetITStatus(TIM2, TIM_IT_Update) == SET)
   {

     TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update);
   }
}

//Tim3
void TIM3_IRQHandler(void)
{
 if (TIM_GetITStatus(TIM3, TIM_IT_Update) == SET)
 {
   

   TIM_ClearITPendingBit(TIM3, TIM_FLAG_Update);
 }
}

//Tim12(控制)
void TIM8_BRK_TIM12_IRQHandler(void)
{
 if (TIM_GetITStatus(TIM12, TIM_IT_Update) == SET)
 {
		
		control_Config();
    Usart_SendArray(USART1,&Res,3); 
	  // Usart_SendByte(USART1,Res[0]);
	 
    TIM_ClearITPendingBit(TIM12, TIM_FLAG_Update);
 }
}

void USART1_IRQHandler(void)
{
  u8 data;
  if(USART_GetITStatus(USART1,USART_IT_RXNE) != RESET)
  {
    data =USART_ReceiveData(USART1);


    if (usart_run == 1)
    {
      Res[t++] = data;
    }
    
    USART_ClearITPendingBit(USART1, USART_IT_RXNE);
    if(data == '1')
    {		
      usart_run = 1;
      usart_finish = 0;
    }
    else if(data == '0')
    {
      usart_run = 0;
      usart_finish = 1;
      t = 0;
    }
		// Usart_SendArray(USART1,&Res,5);  
    while(USART_GetFlagStatus(USART1,USART_FLAG_TC) ==RESET); 
  
    }
  }





/******************************************************************************/
/*                 STM32F10x Peripherals Interrupt Handlers                   */
/*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  */
/*  available peripheral interrupt handler's name please refer to the startup */
/*  file (startup_stm32f10x_xx.s).                                            */
/******************************************************************************/

/**
  * @brief  This function handles PPP interrupt request.
  * @param  None
  * @retval None
  */
/*void PPP_IRQHandler(void)
{
}*/

/**
  * @}
  */ 


/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
